<?php

namespace app\api\controller;

use think\Controller;
use think\Db;

class BaseController extends Controller
{
	public $user = [];
	public $user_id = 0;
	/**
	 * 返回信息
	 */
	public function ApiResult($status=true,$code=10000,$msg="获取成功",$arr=[])
	{
		echo json_encode(['status' => $status, 'code' => $code, 'msg' => $msg, 'result' => $arr]);exit;
	}	

	public function checkUser()
	{
		$token = input('server.HTTP_TOKEN');
		if (empty($token)) {
			$this->ApiResult(false,789,'请先登录');
		}

		$user_info = Db::name('shop_user')->where('token', $token)->find();
		if (empty($user_info) || empty($user_info['user_id'])) {
			$this->ApiResult(false,789,'用户不存在，请重新登录');
		}

		$this->user = $user_info;
		$this->user_id = $user_info['user_id'];
	}
}
